package com.wuchao.servlet143;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

/**
 * @author 吴超66
 * 注解
 * @version 1.0
 * @date 2022/4/22 10:19
 */
@WebServlet(name = "PojoController",urlPatterns = "/PojoController",
initParams = {@WebInitParam(name="username",value ="cg"),
        @WebInitParam(name="pwd",value ="123")})//局部注解
//这就是注解 1叫什么 2类在哪里 3怎么掉我
public class PojoController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();//文件流
        out.println("我爱你143");
        out.println("<script>");
        out.println("alert(\"我是真的想你们好\");");
        out.println("</script>");

        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //一定会乱码
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();//文件流
        //String username = this.getServletConfig().getInitParameter("username");//cc局部
       //Enumeration<String> initParameterNames = getServletConfig().getInitParameterNames();
      //全局
       // this.getServletConfig().getServletContext().getInitParameter("username")
        out.println();
        String name = request.getParameter("name");
        if(name.equals("cc")){
            request.getRequestDispatcher("/demo7/login.jsp?f1=1").forward(request,response);
        }else{
            response.sendRedirect(request.getContextPath()+"/demo7/login.jsp?f2=1");
        }

        out.flush();
        out.close();
    }
}
